@()(implicit session: Session)
@data.main("数据管理") {

    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li>
                <b style="font-size: 20px;">数据</b>
            </li>
            <li style="margin-left: 2em;">
                <a href="routes.BackgroundController.dataUploadBefore()" ><i class="fa fa-cloud-upload"></i>
                    数据导入</a>
            </li>

            <li style="margin-left: 2em;">
                <a href="routes.BackgroundController.manageBefore()"><i class="fa fa-sliders"></i>
                    数据编辑</a>
            </li>
        </ul>
    </div>


    <div class="row-fluid">

        <div class="row">

            <div class="col-md-12 col-sm-12">
                <div class="portlet blue-soft box">

                    <div class="portlet-title">
                        <div class="caption">
                            数据编辑
                        </div>
                    </div>

                    <div class="portlet-body">

                        <div id="toolbar"></div>

                        <table class="table table-bordered table-hover " id="table" data-pagination="true" data-search="true"
                        data-toolbar="#toolbar" data-page-list="[10, 25, 50, 100, all]" data-search-align="left" data-multiple-search="true"
                        ></table>

                    </div>
                </div>
            </div>
        </div>
    </div>


    <script>


            $(function () {

/*
                var result = [];

                $.ajax({
                    url: "routes.BackgroundController.getAllTeacherName()",
                    async: false,
                    type: "get",
                    success: function (data) {
                        $.each(data, function (k, v) {
                            result.push({
                                value: v.id,
                                text: v.name
                            })
                        });
                    }
                });
*/


                $("#table").bootstrapTable({
                    columns: [{
                        field: 'operation',
                        title: '操作',
                        formatter: function (value, row, index) {
                            var de = "<button class='delete' onclick='openDelete(this)' value=\"" + row.id + "\" id='" + row.id + "' title='删除'><i class='fa fa-trash'></i></button>";
                            return de;
                        }
                    },{
                        field: 'id',
                        title: 'ID'
                    }, {
                        field: 'bacteriaNameCh',
                        title: '菌株名称（中文）'
                    }, {
                        field: 'bacteriaNameEn',
                        title: '菌株名称（英文）'
                    }, {
                        field: 'preservedPeople',
                        title: '保藏人'
                    }, {
                        field: 'teacher',
                        title: '指导老师'/*,
                        editable: {
                            type: "select",
                            title: "指导老师",
                            source: result
                        }*/
                    }, {
                        field: 'isSercet',
                        title: '是否保密'
                    }, {
                        field: 'preservedDate',
                        title: '保藏日期'
                    }],
                    onEditableSave: function (field, row) {
                        $.ajax({
                            url: "routes.BackgroundController.updateTeacher()",
                            type: "post",
                            dataType: "json",
                            data: {
                                "id": row.id,
                                "teacher": row.teacher
                            }
                        });
                    }
                });

                reloadData();
            });

            function reloadData() {
                $.ajax({
                    url: "routes.BackgroundController.getAllData()",
                    type: "post",
                    success: function (data) {
                        $("#table").bootstrapTable("load", data)
                    }
                });
            }

            function openDelete(obj) {

                swal({
                            title: '删除?',
                            text: "删除后将不能恢复 \"" + obj.id + "\" 号样本!",
                            type: 'warning',
                            showCancelButton: true,
                            confirmButtonColor: '#3085d6',
                            cancelButtonColor: '#d33',
                            confirmButtonText: '确认删除!',
                            cancelButtonText: "取消",
                            closeOnConfirm: false
                        }, function () {
                            $.ajax({
                                url:"/bacteria/admin/deleteBacteriaById?id=" + obj.id,
                                type : "delete",
                                success:function (data) {
                                    if(data.valid == "false"){
                                        swal("错误",data.message,"error")
                                    }else{
                                        swal({
                                            type: "success",
                                            title: "\n",
                                            text:"删除成功！"
                                        },function () {
                                            reloadData();
                                        })
                                    }
                                }
                            })
                        }
                )
            }




    </script>
}